<template>
   <div>

    <label>输入：</label>
    <input v-model="val" style="font-size:20px;"/>
    <br/>
    <span>{{val}}</span>

    <div>
        {{ this.$store.state.data1 }}
    </div>
   </div>
</template>

<script>
export default {
    name:'InputV2',
    props:{
        text:String
    },
    data(){
        return {
            val:''
        }
    },
    mounted(){

    },
    methods:{
        getdata2(data){
            console.log('~~~~~~~inputv2~~~~getdata2~~~~~~~~~');
        }
    },
    watch:{
        val(val){
            console.log("~~~~~~~~~~~~~~"+val);

            this.$store.state.data2 = {'name':'jim'+val};

// dispatch：含有异步操作，例如向后台提交数据，写法： this.$store.dispatch('action方法名',值)
// commit：同步操作，写法：this.$store.commit('mutations方法名',值)

            this.$store.commit('getdata1',{name:'lll'});//掉对方的方法
        }
    },
    created(){
       
    }
}
</script>


<style scoped>

</style>